<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        
        <title></title>
        
                    <head>
                        <link href="style3.css" rel="stylesheet" type="text/css" />
                    </head> 
               
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>

            <?php
            //Author Lana Nawzad
            //take the member id in a session
            session_start();
            $memberid = $_SESSION['member_id'];
           // echo $memberid;

            //open connection
            mysql_connect("localhost", "root", "") or die("Connection Failed");
            mysql_select_db("mydb") or die("Connection Failed");
            // if the conference id from the referred page is available
            if (isset($_GET['conference_id'])) {
                // Get the conference id from the referred page
                $confid = intval($_GET['conference_id']);
                
                // select the longname of the conference opened and fetch it
                $getConfName = mysql_query("SELECT long_name FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
                $getConflongname = mysql_fetch_assoc($getConfName);
                // set the long name of the conference by a variable and then print it
                $ConfLongName = $getConflongname['long_name'];
                echo "<h1> $ConfLongName </h1>";
            }  
            ?> 
           
        

        <form name="myform" action="" method="POST">
            <tr>
                <td>
                    <div align="center"><br>
                        <input type ="submit" name ="Subscribe" value ="Subscribe" />
                    </div>
                </td>
            </tr>

            <?php
            if (isset($_POST['Subscribe'])) {
                ?>
                <div align="center"><br>
                    <input type="radio" name="type" value="O"> Organizer<br>
                    <input type="radio" name="type" value="R"> Reviewer<br>
                    <input type ="submit" name ="done" value ="Ok!" />
                </div>
                <?php
            }
            //after the user chooses which type he wants to be he should press the done button
            if (isset($_POST['done'])) {
                if ($_POST['type'] == null) {
                    echo 'please choose the role you want to be';
                } else {
                    $type = $_POST['type'];
                    subscribe_to_conference($memberid, $confid, $type);
                }
            }
            //this function is called inside the action of the button, it check whether this user is the type he asks to be or not and if not it saves his request in the database
            function subscribe_to_conference($member_id, $conference_id, $type) {

                $con = mysql_connect("localhost", "root", "");
                if (!$con) {

                    die('Could not connect:' . mysql_error());
                }
                mysql_select_db("mydb", $con);

                if ($type == 'O') {
                    //Get the organizer id
                    $privileges_id_organizer = mysql_query("SELECT privileges_id from privileges where role = 'organizer'")
                            or die(mysql_error());
                    While ($row = mysql_fetch_assoc($privileges_id_organizer)) {
                        $privileges_id = $row['privileges_id'];
                    }
                    //check whether this member is subscribed in this conference as an organizer or not
                    $check_organizer = mysql_query("SELECT* FROM Member_Privileges 
                       WHERE member_id ='$member_id' AND privileges_id ='$privileges_id' AND conference_id ='$conference_id'") or die(mysql_error());
                    $row = mysql_fetch_assoc($check_organizer);
                    //if the rows are greater than one then he is an organizer in this conference
                    if ($row > 1) {
                        echo 'You are already an organizer in this conference';
                    }//this member is not an organizer 
                    else {
                        //check whether this member sent a request before
                        $check_organizerRequest = mysql_query("SELECT* FROM  Member_SubscribesTo_Conference 
                       WHERE member_id ='$member_id' AND conference_id ='$conference_id' AND request_type='O'") or die(mysql_error());
                        $row = mysql_fetch_assoc($check_organizerRequest);
                        //if the rows are greater than one then he has sent a request in this conference
                        if ($row > 1) {
                            echo 'You already sent a request to become an organizer';
                        }//this member is not an organizer 
                        else {
                            //add his request in table Member_SubscribesTo_Conference
                            $addRequest = mysql_query("INSERT INTO Member_SubscribesTo_Conference(member_id, conference_id, request_type)
                    VALUES ('$member_id','$conference_id','O')")
                                    or die(mysql_error());
                            echo 'Your request is sent to the main conference organizer';
                        }
                    }
                }
                if ($type == 'R') {
                    //Get the reviewer id
                    $privileges_id_reviewer = mysql_query("SELECT privileges_id from privileges where role = 'reviewer'")
                            or die(mysql_error());
                    While ($row = mysql_fetch_assoc($privileges_id_reviewer)) {
                        $privileges_id = $row['privileges_id'];
                    }
                    //check whether this member is subscribed in this conference as a reviewer or not
                    $check_reviewer = mysql_query("SELECT* FROM Member_Privileges 
                       WHERE member_id ='$member_id' AND privileges_id ='$privileges_id' AND conference_id ='$conference_id'") or die(mysql_error());
                    $row = mysql_fetch_assoc($check_reviewer);
                    //if the rows are greater than one then he is a reviewer in this conference
                    if ($row > 1) {
                        echo 'You are already a reviewer in this conference';
                    }//this member is not a reviewer
                    else {
                        //check whether this member sent a request before
                        $check_reviewerRequest = mysql_query("SELECT* FROM  Member_SubscribesTo_Conference 
                       WHERE member_id ='$member_id' AND conference_id ='$conference_id' AND request_type='R'") or die(mysql_error());
                        $row = mysql_fetch_assoc($check_reviewerRequest);
                        //if the rows are greater than one then he has sent a request in this conference
                        if ($row > 1) {
                            echo 'You already sent a request to become a reviewer';
                        } else {
                            //add his request in table Member_SubscribesTo_Conference
                            $addRequest = mysql_query("INSERT INTO Member_SubscribesTo_Conference(member_id, conference_id, request_type)
                    VALUES ('$member_id','$conference_id','R')")
                                    or die(mysql_error());
                            echo 'Your request is sent to the main conference organizer';
                        }
                    }
                }
            }
            ?>
<?php
//Author Lana Nawzad
?>
            <form action= "" method="post" enctype="multipart/form-data" onsubmit="return validate(this)" >

                <br>
                <br>
                <br>
                <h3><strong> Place of Conference: </strong></h3>
                <?php
                //select what is written in place of that conference and fetch it
                $getPlace = mysql_query("SELECT Place FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
                $getConfPlace = mysql_fetch_assoc($getPlace);
                // set the place of that conference by a variable and print it
                $Place = $getConfPlace['Place'];
				 echo "<table>
                <tr>
                <td>{$Place}</td>
				 </tr>";
				 echo  '</table>'; 
                ?>
                </br>

                 <h3> <strong>Description:</strong></h3>
                <?php
                //select what is written in description of that conference and fetch it
                $getDescription = mysql_query("SELECT description FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
                $getConfDescription = mysql_fetch_assoc($getDescription);
                // set the description of that conference by a variable and print it
                $Describe = $getConfDescription['description'];
				
                echo "<table>
                <tr>
                <td>{$Describe}</td>
				 </tr>";
				 echo  '</table>'; 
                ?>
                </br>
                 <h3><strong> Call for papers:</strong></h3>
                <?php
                //select what is written in call for papers of that conference and fetch it
                $getCallforText = mysql_query("SELECT call_for_papers_text FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
                $getCallpaperText = mysql_fetch_assoc($getCallforText);
                
                // set the call for paper text of that conference by a variable and print it
                $callforpaper = $getCallpaperText['call_for_papers_text'];
                if($callforpaper == NULL)
                {
                    echo 'There is no call for paper text decided yet!';
                }
                else
                {
				 echo "<table>
                <tr>
                <td>{$callforpaper}</td>
				 </tr>";
				 echo  '</table>'; 
                }
                ?>
                </br


                <html> 
                    <head>
                        <link href="style3.css" rel="stylesheet" type="text/css" />
                    </head> 
                </html>

                <?php
                //select the review start date of that conference 
                $getRevStartDate = mysql_query("SELECT rev_startDate FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
                //$getRevDeadline = mysql_fetch_assoc($getDeadline);
                //select the review end date of that conference 
                $getRevEndDate = mysql_query("SELECT rev_endDate FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
				 $getconfDate = mysql_query("SELECT conference_date FROM conference WHERE conference_id = '$confid'") or die(mysql_error());
               
                //printing the header of the table
				echo '<h3><strong>Timeline:</strong></h3>';
                echo '<table width="100%">
                <tr>
                <td><b>Review Start Date</b></td>
                <td><b>Review End Date</b></td>
				<td><b>Conference Date</b></td>

                </tr>';

                //Printing the data 
                while (($getRevStDate = mysql_fetch_assoc($getRevStartDate)) && ($getRevEDate = mysql_fetch_assoc($getRevEndDate)) && $getConfDate= mysql_fetch_assoc($getconfDate)) {
              // printing the review start and end dates of papers in that conference 
                    echo "<tr>
                </br>
                <td>{$getRevStDate['rev_startDate']}</td>
                <td>{$getRevEDate['rev_endDate']}</td>   
				<td>{$getConfDate['conference_date']}</td>
                </tr>";
                }
                // Close table
                echo '</table>';   
                ?>
                </br>
                
                <?php
					echo '<h3> <strong>Submssions Deadlines:</strong></h3>';
                // select the categories and submission deadlines of each one in that conference
                $getCategoryInf = mysql_query("SELECT category,submission_date 
                                               FROM category C, conference_category CC
                                               WHERE conference_id =  '$confid' && C.category_id = CC.category_id"
                                               ) or die(mysql_error());
                
                //printing the header of the table
                echo '<table width="100%">
                 <tr>
                <td><b>Category</b></td>
                <td><b>Days left for Submission</b></td>
           
                </tr>';

                //Printing the data 
                while ($getCategoryInformation = mysql_fetch_assoc($getCategoryInf)) {
              // set the submission deadline to a string type to be able to do subtraction
                $Submission = strtotime($getCategoryInformation['submission_date']);
                //check if the current date is before the submission deadline
                if (time() < $Submission)
                {
                // The countdown of days by subtra(cting the submission deadline and the current date to get the number of days left to submit
                $daysLeft = $Submission - time();
                // set the number of days left into a variable to get it
                $NumDaysLeft = sprintf("%s days", date('z', $daysLeft));
                
                // printing the catagories and the number of days left to submit a paper in each category in that conference
				
				
                echo "<tr>
                </br>
                <td>{$getCategoryInformation['category']}</td>
                <td>{$NumDaysLeft}</td>
                </tr>";
                }}
                // Close table
                echo '</table>';   
                ?>
                </br>
           <?php
           // Select first_name, second_name 
        $Name= mysql_query ("SELECT first_name, last_name FROM member WHERE member_id = '$memberid' ");
        $row = mysql_fetch_assoc($Name);
				echo '<h3> <strong>Options:</strong></h3>';
        // check if first_name or second_name == NULL
        if($row['first_name']== NULL || $row['last_name']== NULL ) {
        // Call SignUp  
        // Create a link that redirects to the next page which is submission and sending to it the conference

           print " <a href='SignUp.php?from=A&member_id={$memberid}&conference_id={$confid}'>Click here</a>";

               }
          else
          {
           // Create a link that redirects to the next page which is submission and sending to it the conference
           print " <a href='Submission.php?conference_id={$confid}'>Click here to Submit a paper</a>";
          }
          
          $sessions = mysql_query("SELECT * FROM session WHERE conference_id = '$confid'");
           if (mysql_num_rows($sessions)>0){
               echo '</br></br><a href="SessionPage.php?conference_id='.$confid.'">View Conference Sessions.</a>';
           }
           ?>
        
            